package thread;

public class SuncDemo4 {
    public static void main(String[] args) {
        Boo boo = new Boo();
        Thread t1 = new Thread(){
          public void run (){
              boo.methodaA();
          }
        };
        Thread t2 = new Thread(){
            public void run (){
                boo.methodaB();
            }
        };
        t1.start();
        t2.start();
    }
}
class Boo {
    public synchronized void methodaA(){
        try {
            Thread t1 = Thread.currentThread();
            System.out.println("正在执行A方法中");
            Thread.sleep(4000);
            System.out.println("A方法执行完毕");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    //public synchronized void methodaB(){
    public  void methodaB(){
        synchronized(this) {
            try {
                Thread t1 = Thread.currentThread();
                System.out.println("正在执行B方法中");
                Thread.sleep(4000);
                System.out.println("B方法执行完毕");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
